const express = require('express');
const router = require('./router');
const middlewares = require('./middleware');
const logger = require('morgan');
const Utils = require('./utils');
const app = express();
  // liwei master
app.use(middlewares.dev_env); // 本地开发跨域
app.use(logger('dev', {
  stream: Utils.Logger
}));
app.use(express.json());
app.use(express.urlencoded({
  extended: false
}));
app.use(middlewares.record()); // 记录所有入参和返参
router(express, app); // 路由配置
app.use(middlewares._404());
app.use(middlewares._err());


// 捕获错误
process.on('uncaughtException', err => console.log(err));
process.on('unhandledRejection', err => console.log(err));


module.exports = app;